﻿using System.Web.Mvc;
using SDCloudSolution.SDCloud.Web.Infrastructure.Interfaces;
using SDCloudSolution.SDCloud.Web.Models.Layout;

namespace SDCloudSolution.SDCloud.Web.Controllers
{
    [ChildActionOnly]
    [Authorize]
    public partial class LayoutController : Controller
    {
        private readonly IUserIdentityProvider _userIdentityProvider;

        public LayoutController(IUserIdentityProvider userIdentityProvider)
        {
            _userIdentityProvider = userIdentityProvider;
        }

        [ChildActionOnly]
        public virtual ActionResult TopMenu(ControllerBase baseController)
        {
            var model = new MenuViewModel
            {
                /*
                 * Seeting current usr name to show on the UI
                 */
                CurrentUserName = _userIdentityProvider.Current.UserName,

                /*
                 * Cunfiguring main menu items
                 */
                Items = new[]
                {
                    new MenuItemViewModel
                    {
                        Title = "Dashboard",
                        IconCssClass = "fa fa-lg fa-th-large",
                        TargetAction = MVC.Dashboard.Index(),
                        ControllerType = typeof(DashboardController)
                    },
                    new MenuItemViewModel
                    {
                        Title = "Gallery",
                        IconCssClass = "fa fa-lg fa-shopping-bag",
                        TargetAction = MVC.ModelsGallery.List().Result,
                        ControllerType = typeof(ModelsGalleryController)
                    },
                    new MenuItemViewModel
                    {
                        Title = "My models",
                        IconCssClass = "fa fa-lg fa-cubes",
                        TargetAction = MVC.Models.List().Result,
                        ControllerType = typeof(ModelsController)
                    },
                    new MenuItemViewModel
                    {
                        Title = "My model runs",
                        IconCssClass = "fa fa-lg fa-history",
                        TargetAction = MVC.ModelRuns.List().Result,
                        ControllerType = typeof(ModelRunsController)
                    }
                }
            };

            foreach (var item in model.Items)
            {
                item.IsActive = item.ControllerType.IsInstanceOfType(baseController);
            }

            return PartialView(model);
        }
    }
}